#!/usr/bin/env python
# -*- coding: utf-8 -*-
from lib.format_time import *
from lib.HandleMysql import *
from lib.handle_mongo import *
from lib.switch_code import *
from lib.load_data import *
from topinfo_conn import *
import sys
import re
import time
reload(sys)
sys.setdefaultencoding('utf-8')



def get_citys(city):
    conn = dict_conn()

    if city == 0 :
        return None

    query = 'select fullpath from t_local where localid=%s' % city
    items = conn.get_results(query)
    fullpath = None
    if len(items)>0:
        fullpath = items[0][0]
    
    if fullpath is None:
        return None
    
    query = "select localid, localname from t_local where localid in (%s) order by depth asc" % fullpath
    #print q
    rs = conn.get_results(query)
    conn.close()
    return rs

def get_cates(cate):

    conn = dict_conn()
    if cate == 0 :
        return None

    query = 'select fullpath from t_category where cateid=%s' % cate
    items = conn.get_results(query)
    fullpath = None
    if len(items)>0:
        fullpath = items[0][0]
    
    if fullpath is None:
        return None
    
    query = "select cateid, catename from t_category where cateid in (%s) order by depth asc" % fullpath
    #print q
    rs = conn.get_results(query)
    conn.close()
    return rs